var url;
function newUser(){
    $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增产品信息');
    $('#fm').form('clear');
    url = '/Lease/saveProduct.json';
}
function editUser(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','修改产品信息');
        $('#fm').form('load',row);
        url = '/Lease/editProduct.json?id='+row.id;
    }
}
function saveUser(){
    $('#fm').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            if (result == "fail"){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}
function doSearch(){
    $("#dg").datagrid("load",{
        name:$("#productName").val(),
        model:$("#productModel").val()
    });
}
$(function(){
    $("#dg").datagrid({
        columns:[[
            {field:'id',title:'ID',width:60},
            {field:'name',title:'名称',width:60},
            {field:'model',title:'型号',width:60},
            {field:'price',title:'单价(元/天)',width:60},
            {
                field:'once',
                title:'一次性服务',
                width:60,
                formatter:function(value,row,index){
                    if(value){
                        return "是";
                    }else{
                        return "否"
                    }
                }
            },
            {field:'remark',title:'备注',width:60}
        ]]
    });
})
